home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 3_14.lha / 3_14 / 3_14c2.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  900b  |  49 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <string.h>
  6. har *get_funcdefn()
  7.  
  8.    const chunksize = 128;
  9.    int slen = chunksize;
  10.    char *s = new char[slen];
  11.    char *sp = s;
  12.    char ch;
  13.  
  14.    for (;;)    // loop until end of definition
  15. {
  16. if (!cin.get(ch))    // oops, EOF
  17.     {
  18.     curr_tok = END;
  19.     return 0;
  20.     }
  21.  
  22. if (ch == LB)        // another oops
  23.     {
  24.     error("no recursively defined functions");
  25.     curr_tok = PRINT;
  26.     return 0;
  27.     }
  28.  
  29. if (ch == RB)        // found end
  30.     {
  31.     *sp = '\0';
  32.     (void) get_token();    // skip RB
  33.     return s;
  34.     }
  35.  
  36. *sp++ = ch;
  37. if (sp - s >= slen)    // check for buffer end
  38.     {            // and reallocate space
  39.     int oslen = slen;
  40.     slen += chunksize;
  41.     char *t = new char[slen];
  42.     memcpy(t, s, oslen);
  43.     delete [oslen] s;
  44.     s = t;
  45.     sp = s + oslen;
  46.     }
  47. }
  48.  
  49.